import 'me_menu_item.dart';

class MeMenu {
  List<MeMenuItem> baseMenuList;
  List<MeMenuItem> majorMenuList;
  List<MeMenuItem> subMenuList;

  // 带参数的构造函数
  MeMenu({
    this.baseMenuList = const [],
    this.majorMenuList = const [],
    this.subMenuList = const [],
  });

  // 命名构造函数用于从 JSON 解析
  factory MeMenu.fromJson(Map<String, dynamic> json) {
    return MeMenu(
      baseMenuList: (json['baseMenuList'] as List<dynamic>?)
          ?.map((item) => MeMenuItem.fromJson(item))
          .toList() ??
          [],
      majorMenuList: (json['majorMenuList'] as List<dynamic>?)
          ?.map((item) => MeMenuItem.fromJson(item))
          .toList() ??
          [],
      subMenuList: (json['subMenuList'] as List<dynamic>?)
          ?.map((item) => MeMenuItem.fromJson(item))
          .toList() ??
          [],
    );
  }

  // 转换为 JSON 方法
  Map<String, dynamic> toJson() {
    return {
      'baseMenuList': baseMenuList.map((item) => item.toJson()).toList(),
      'majorMenuList': baseMenuList.map((item) => item.toJson()).toList(),
      'subMenuList': baseMenuList.map((item) => item.toJson()).toList(),
    };
  }
}
